package com.bridgeintelligent.tag.bulkload.service.core.threadpool;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by JackCheung on 2019/9/19 8:05 PM.
 */
@Component
public class ThreadPoolBean {

    @Bean("threadPool_realTime")
    public Executor threadPool() {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("bulkLoad-%d")
                                                                .build();
        BlockingQueue<Runnable> blockingQueue = new LinkedBlockingQueue<>(Integer.MAX_VALUE);
        return new ThreadPoolExecutor(6, 12, 10, TimeUnit.SECONDS, blockingQueue, threadFactory);
    }
}
